use minigrep::Config;

use std::{env, process};

fn main() {
    let args: Vec<String> = env::args().collect();
    println!("{:?}", args);

    let config = Config::new(&args).unwrap_or_else(|err| {
        // eprintln 打印错误信息到到标准错误流
        eprintln!("Problem parsing arguments: {}", err);
        process::exit(1);
    });

    println!("searching for {}", config.query);
    println!("in file  {}", config.filename);

    // Config没有实现Copy的trait，所以调用run函数时config的所有权会移动
    if let Err(e) = minigrep::run(config) {
        eprintln!("Application error: {}", e);

        process::exit(1);
    }

    // println!("searching for {}", config.query);
}
